﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace QuickManager.Code
{
    public class Hotkey
    {
        /// <summary>
        /// 快捷键消息
        /// </summary>
        public const int WM_HOTKEY = 0x0312;

        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool UnregisterHotKey(IntPtr hWnd, int id);

        [DllImport("kernel32.dll", EntryPoint = "GlobalAddAtomW")]
        private static extern int GlobalAddAtomW(string name);

        [Flags()]
        public enum KeyModifiers
        {
            None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            Windows = 8
        }

        public static int GlobalAddAtom(string name)
        {
            return GlobalAddAtomW(name) - 0xC000;
        }
    }
}
